package operations;

import entity.Student;
import entity.StudentList;

import java.util.List;
import java.util.Scanner;

// 查询学生信息, 根据 id 来查询
public class Search implements IOperation {

    @Override
    public Student work() {
        // 得到学生数组
        List<Student> studentList = StudentList.getInstance();

        Scanner in = new Scanner(System.in);
        System.out.println("请输入要查找的学生的学号: ");
        String id = in.next();

        // 遍历这个数组
        for (Student student : studentList) {
            if (student.getId().equals(id)) {
                System.out.println("查询成功, 这个学生的信息为: ");
                System.out.println(student);
                return student;
            }
        }
        System.out.println("未查询到该学生的信息");
        return null;
    }
}
